package com.scproject.exceptions;

import com.auth0.jwt.exceptions.JWTVerificationException;
import com.scproject.dto.ResponseDto;
import com.scproject.scbef.exception.ProcessException;
import com.scproject.scbef.pojo.vo.ResponseCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author LNL
 * @date 2021/4/27 16:25
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(ProcessException.class)
    public ResponseDto handlerProcessException(ProcessException e) {
        log.info(e.getMessage());
        String msg = e.getMsg();
        if(msg == null || "".equals(msg)) {
            msg = "服务器异常";
        }
        ResponseDto responseDto = new ResponseDto(ResponseCodeEnum.ERROR.toString(), msg);
        return responseDto;
    }


    @ResponseBody
    @ExceptionHandler(Exception.class)
    public ResponseDto handler(Exception e) {
        log.info(e.getMessage());
        String msg = e.getMessage();

        if(msg == null || "".equals(msg)) {
            msg = "服务器异常";
        }
        ResponseDto responseDto = new ResponseDto(ResponseCodeEnum.ERROR.toString(), msg);
        return responseDto;
    }

}
